package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.VideoComment;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jh
 * 2018/7/19 9:40
 */
@Repository
public class VideoCommentDao {

	@Resource
	private SqlSession sqlSession;


	@Operate("strategy('byVideoId',#videoId)")
	public Integer countVideoComment(Long videoId) {
		Map<String, Object> map = new HashMap<>(2);
		map.put("videoId", videoId);
		return sqlSession.selectOne("countVideoComment", map);
	}

	@Operate("strategy('byVideoId',#videoId)")
	public List<VideoComment> listVideoComment(Long videoId, Integer offset, Integer pageSize) {
		Map<String, Object> map = new HashMap<>(4);
		map.put("videoId", videoId);
		map.put("offset", offset);
		map.put("pageSize", pageSize);
		return sqlSession.selectList("listVideoComment", map);
	}

	@Operate("strategy('byVideoId',#videoId)")
	public void saveVideoComment(VideoComment videoComment, Long videoId) {
		sqlSession.insert("saveVideoComment", videoComment);
	}

}
